// pages/particulars-new/particulars-new.js
var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    id: '',
    info: {}
  },
  onLoad: function(options) {
    console.log(options)
    var _this = this
    _this.setData({
      id: options.id
    })
    _this.onCounponInfo()
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  onCounponInfo() {
    var Б = this,
      id = Б.data.id,
      url = app.link.orderCentent + id + '.st'
    com.link(url, {}, function(rep) {
      console.log(rep);
      Б.setData({
        info: rep.data.data
      })
    }, 'GET')

  },
  codeList: function(e) {
    let index = e.currentTarget.dataset.index;
    let _this = this
    if (index == 0) {
      wx.showModal({
        title: '温馨提示',
        content: '确认拒绝订单吗？',
        success(res) {
          if (res.confirm) {
            com.link(app.link.hendOder + e.currentTarget.id + '.st', {}, function(rep) {
              console.log(rep)
              if (!rep.data.state) {
                wx.showModal({
                  title: '温馨提示',
                  content: rep.data.message,
                })
                return false;
              }
              wx.showToast({
                title: '操作成功',
                icon: 'success'
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 1500)
            }, 'GET')
          }
        }
      })
    }
    if (index == 1) {
      var id = _this.data.id,
        url = app.link.acceptOrder + id + '.st',
        data = {}
      wx.showModal({
        title: '温馨提示',
        content: '确认接单吗？',
        success(e) {
          if (e.confirm) {
            com.link(url, data, function(rep) {
              console.log(rep)
              if (rep.data.state) {
                wx.showToast({
                  title: '接单成功',
                  icon: 'success'
                })
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1500)
              } else {
                wx.showToast({
                  title: rep.data.message,
                  icon: 'none'
                })
              }
            }, "GET")
          }
        }
      })
    }
  },
})